home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / games / pupworld.swf / scripts / __Packages / Heroes / WorldObject.as < prev   
Encoding:
Text File  |  2011-06-09  |  3.2 KB  |  140 lines

  1. class Heroes.WorldObject extends MovieClip
  2. {
  3.    var zMin;
  4.    var zMax;
  5.    var zdx;
  6.    var zdy;
  7.    var g;
  8.    var dyMax;
  9.    var scale;
  10.    var windowWidth;
  11.    var dy;
  12.    var y;
  13.    var z;
  14.    var x;
  15.    var graphics;
  16.    var shadowY;
  17.    var doScale;
  18.    var hasFoundShadow = false;
  19.    var isGrabbed = false;
  20.    function WorldObject()
  21.    {
  22.       super();
  23.       this.zMin = 0;
  24.       this.zMax = 350;
  25.       this.zdx = 0;
  26.       this.zdy = 0.6;
  27.       this.g = -1.5;
  28.       this.dyMax = -20;
  29.       this.scale = 1.3;
  30.       this.windowWidth = 470;
  31.       this.dy = 0;
  32.       if(this.y == -1)
  33.       {
  34.          this.y = 0;
  35.       }
  36.       if(this.z == -1)
  37.       {
  38.          this.z = int((400 - this.y - this._y) / this.zdy);
  39.       }
  40.       if(this.x == -1)
  41.       {
  42.          this.x = int(this._x - this.z * this.zdx);
  43.       }
  44.       this._visible = false;
  45.    }
  46.    function onEnterFrame()
  47.    {
  48.       if(this._visible)
  49.       {
  50.          this.limitZ();
  51.          this.fall();
  52.          this.updatePosition();
  53.          this._parent.updateDepth(this,Math.round(400 - this.z));
  54.          if(this.hasFoundShadow)
  55.          {
  56.             this.graphics.shadow._y = this.shadowY + this.y;
  57.          }
  58.          else if(typeof this.graphics.shadow == "movieclip")
  59.          {
  60.             this.hasFoundShadow = true;
  61.             this.shadowY = this.graphics.shadow._y;
  62.          }
  63.       }
  64.    }
  65.    function fall()
  66.    {
  67.       if(!this.isGrabbed)
  68.       {
  69.          this.dy += this.g;
  70.          if(this.dy < this.dyMax)
  71.          {
  72.             this.dy = this.dyMax;
  73.          }
  74.          this.y += this.dy;
  75.          if(this.y < 0)
  76.          {
  77.             this.y = 0;
  78.             this.dy = 0;
  79.          }
  80.       }
  81.    }
  82.    function limitZ()
  83.    {
  84.       if(this.z < this.zMin)
  85.       {
  86.          this.z = this.zMin;
  87.       }
  88.       if(this.z > this.zMax)
  89.       {
  90.          this.z = this.zMax;
  91.       }
  92.    }
  93.    function get_X(testX, testZ)
  94.    {
  95.       return testX + testZ * this.zdx;
  96.    }
  97.    function get_Y(testY, testZ)
  98.    {
  99.       return 400 - testY - testZ * this.zdy;
  100.    }
  101.    function isOnScreen()
  102.    {
  103.       return this.isXOnScreen(this.x);
  104.    }
  105.    function isXOnScreen(testX)
  106.    {
  107.       var _loc2_ = this._width / 2;
  108.       return testX + _loc2_ > - this._parent._x - 30 && testX - _loc2_ < - this._parent._x + 500;
  109.    }
  110.    function updatePosition()
  111.    {
  112.       var _loc2_ = this.scale + (this.scale - 1) * this.z / -400;
  113.       if(this.doScale)
  114.       {
  115.          this._xscale = 100 * _loc2_;
  116.          this._yscale = 100 * _loc2_;
  117.       }
  118.       var _loc3_ = _loc2_ * (this.x + this._parent._x - this.windowWidth / 2);
  119.       this._x = _loc3_ - this._parent._x + this.windowWidth / 2;
  120.       this._y = 160000 / (this.z + 400);
  121.       if(this.z > 218)
  122.       {
  123.          this._y -= 3;
  124.       }
  125.    }
  126.    function calculateZ(ypos)
  127.    {
  128.       return 160000 / ypos - 400;
  129.    }
  130.    function playSound(soundName)
  131.    {
  132.       if(this._visible && (this._name == "player" || this._parent.player.intelligence > 0 && this._parent._parent.timer.getTime() > 0))
  133.       {
  134.          var _loc2_ = this._x + this._parent._x;
  135.          pi.AudioLibrary.setPan(soundName,Math.round((_loc2_ - 235) / 4));
  136.          pi.AudioLibrary.playSound(soundName,1);
  137.       }
  138.    }
  139. }
  140.